<!--
    试算页面 公共插件

    参数：
    applyNo         申请编号
    isSP            是否是经销商
    quotationId     试算ID
    op              'add'=新增;'view'=查看;'edit'=修改
    isTrail         是否试算
    isSixPeriod     是否满六期
    contractNo      合同编号
    contractForm    试算清单信息

    方法:
    next            试算返回
    backInfo        返回计算结果集
 -->
<template>
    <div class="basis-info">
        <Alert>计算信息</Alert>
        <Form ref="showCalForm" :model="calForm" :lable-width="50" :rules="rulesCalForm">
            <Row>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="请求日期" prop="calculateTime" :label-width="100">
                        <DatePicker type="date" style="width: 150px" format="yyyy-MM-dd" v-model="calForm.calculateTime"
                                    v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="计算日期" prop="executeTime" :label-width="100">
                        <DatePicker type="date" style="width: 150px" format="yyyy-MM-dd" v-model="calForm.executeTime"
                                    :options="optionsexecuteTime" v-bind:disabled="readonlyView"
                                    :holidayModel="readonly" :start-date="startDate"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="提前终止原因" prop="prepaymentType" :label-width="100">
                        <Select v-model="calForm.prepaymentType" style="width:150px" v-bind:disabled="readonlyView">
                            <Option v-for="item in prepaymentTypeList" :value="item.value" :key="item.value"
                                    :label="item.title">
                                {{item.title}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="还款方式" prop="repayMode" :label-width="100">
                        <Select v-model="calForm.repayMode" style="width:150px" v-bind:disabled="readonlyView">
                            <Option v-for="item in repayModeList" :value="item.value" :key="item.value"
                                    :label="item.title">
                                {{item.title}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col :xs="24" :md="24" :lg="16" :xl="12">
                    <div v-if="isSixPeriod">
                        <FormItem label="不满六期原因" prop="shortSixPeriodReason" :label-width="100">
                            <Input style="width: 600px" v-model="calForm.shortSixPeriodReason"
                                   v-bind:disabled="readonlyView"/>
                        </FormItem>
                    </div>
                </Col>
            </Row>
            <Row>
                <Col :xs="24" :md="24" :lg="24" :xl="24">
                    <div style="text-align: center;">
                        <FormItem>
                            <Button type="primary" icon="ios-star-half" @click="calCost" v-if="op!='view'">计算</Button>
                        </FormItem>
                    </div>
                </Col>
            </Row>
        </Form>
        <Alert>结果信息</Alert>
        <Form ref="showResultForm" :model="resultForm" :lable-width="50">
            <Row>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="未偿本金" prop="unpayedCaptial" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.unpayedCaptial"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="逾期租金" prop="overdueAmount" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.overdueAmount"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="利息应收" prop="interestReceivable" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.interestReceivable"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="未付逾期利息" prop="unpayedOverdueInterest" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.unpayedOverdueInterest"
                                     v-bind:disabled="readonly"/>
                        <Button type="primary" icon="md-eye" @click="queryList('tableUnpayedOverdueInterest')">详情
                        </Button>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="提前终止费率" prop="prepaymentRate" :label-width="100">
                        <InputNumber style="width: 150px" v-model="prepaymentRate" v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="提前终止费用" prop="prepaymentCharge" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.prepaymentCharge"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="提前终止金额" prop="prepaymentCost" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.prepaymentCost"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="应计逾期利息" prop="overdueInterestReceivable" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.overdueInterestReceivable"
                                     v-bind:disabled="readonly"/>
                        <!--<Button type="primary" icon="md-eye" @click="queryList('tableOverdueInterestReceivable')">详情</Button>-->
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="杂费" prop="otherCost" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.otherCost" v-bind:disabled="readonly"/>
                        <Button type="primary" icon="md-eye" @click="queryList('tableOtherCost')">详情</Button>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="未分配金额" prop="unusedDeposit" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.unusedDeposit"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6" v-if="!isSP">
                    <FormItem label="豁免单费用" prop="exemptBillCost" :label-width="100">
                        <InputNumber style="width: 150px" :max="exemptBillCostMax" :min="exemptBillCostMin"
                                     v-model="resultForm.exemptBillCost"
                                     v-bind:disabled="!(this.Obj.isDh&&Obj.processStatus==='underReview')"
                                     @on-change="exemptBillCostChange"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="豁免费用" prop="exemptAmount" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.exemptAmount" v-bind:disabled="readonly"/>
                        <Button type="primary" icon="md-eye" @click="queryList('tableExemptAmount')">详情</Button>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="豁免罚息" prop="exemptOverdueInterest" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.exemptOverdueInterest"
                                     v-bind:disabled="readonly"/>
                        <Button type="primary" icon="md-eye" @click="queryList('tableExemptOverdueInterest')">详情
                        </Button>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="12" :lg="8" :xl="6">
                    <FormItem label="应收金额" prop="receivableAmount" :label-width="100">
                        <InputNumber style="width: 150px" v-model="resultForm.receivableAmount"
                                     v-bind:disabled="readonly"/>
                    </FormItem>
                </Col>
            </Row>
        </Form>
        <Button type="primary" @click="openUploadModal">附件信息</Button>
        <UploadFileModal ref="uploadFileModal" :modal="isUploadFileModalOpen" @closeModal="closeModal"
                         :param="fileParams" :isPreview="op=='view'"/>
        <Row style="text-align: center;" v-if="isTrail">
            <Alert>
                <Button type="primary" icon="md-bookmark" @click="save" v-if="op!='view'">保存</Button>
                <Button type="primary" icon="md-backspace" @click="close">返回</Button>
            </Alert>
        </Row>

        <Modal
            v-model="isShow"
            :title="titleModal"
            :width="960"
            :closable="false"
            :mask-closable="false">
            <rui-page :defines="defines">
                <!-- 未付逾期利息 -->
                <rui-table :defineId="'defineBasicPenaltyInterest'"
                           :showIndex="false"
                           :columns="basicRepaymentPlanColumns"
                           :select="false"
                           @loadDatas="queryUnpayedOverdueInterestDetail"
                           ref-query="searchFormBasicRepaymentPlan"
                           ref="tableUnpayedOverdueInterest"
                           v-show="isShowBasicRepaymentPlan"
                >
                </rui-table>
                <!--应计逾期利息-->
                <rui-table :defineId="'defineBasicPenaltyInterest'"
                           :showIndex="false"
                           :columns="basicPenaltyInterestColumns"
                           :select="false"
                           @loadDatas="queryOverdueInterestReceivableDetail"
                           ref-query="searchFormBasicPenaltyInterest"
                           ref="tableOverdueInterestReceivable"
                           v-show="isShowBasicPenaltyInterest"
                >
                </rui-table>
                <!-- 杂费 -->
                <rui-table :defineId="'defineBasicExpenseRecord'"
                           :showIndex="false"
                           :columns="basicExpenseRecordColumns"
                           :select="false"
                           @loadDatas="queryOtherCostDetail"
                           ref-query="searchFormBasicExpenseRecord"
                           ref="tableOtherCost"
                           v-show="isShowOtherCost"
                >
                </rui-table>
                <!-- 豁免费用 -->
                <rui-table :defineId="'defineManageCostExempt'"
                           :showIndex="false"
                           :columns="manageCostExemptColumns"
                           :select="false"
                           @loadDatas="queryExemptAmountDetail"
                           ref-query="searchFormBasicExpenseRecord"
                           ref="tableExemptAmount"
                           v-show="isShowExemptAmount"
                >
                </rui-table>
                <!-- 豁免罚息 -->
                <rui-table :defineId="'defineManagePenaltyExempt'"
                           :showIndex="false"
                           :columns="managePenaltyExemptColumns"
                           :select="false"
                           @loadDatas="queryExemptOverdueInterestDetail"
                           ref-query="searchFormBasicExpenseRecord"
                           ref="tableExemptOverdueInterest"
                           v-show="isShowExemptOverdueInterest"
                >
                </rui-table>
            </rui-page>
            <div slot="footer">
                <Button size="small" @click="closeModle">取消</Button>
            </div>
        </Modal>

    </div>
</template>


<script>

    import basicRepaymentPlanDefine from "./defines/basic-repayment-plan-define.js";
    import basicPenaltyInterestDefine from "./defines/basic-penalty-interest-define.js";
    import basicExpenseRecordDefine from "./defines/basic-expense-record-define.js";
    import manageCostExemptDefine from "./defines/manage-cost-exempt-define.js";
    import managePenaltyExemptDefine from "./defines/manage-penalty-exempt-define.js";

    import {
        calSettleResult,
        getBatchDate,
        getPrepaymentRate,
        getStaySettleDetailById,
        queryExemptAmountDetail,
        queryExemptOverdueInterestDetail,
        queryOtherCostDetail,
        queryOverdueInterestReceivableDetail,
        queryUnpayedOverdueInterestDetail,
        saveStaySettle,
    } from "@/projects/basic/api/contract/clearance/stay-settle";

    import {getDictDataByType,} from "_p/basic/api/admin/datadic";

    import UploadFileModal from "_p/basic/pages/contract/common/uploadFileModal/uploadFileModal";

    export default {
        components: {
            UploadFileModal,
        },
        name: "startSettle",
        props: {
            //状态
            op: {
                type: String,
                required: true,
                default: 'view'
            },
            //是否试算
            isTrail: {
                type: Boolean,
                required: true,
                default: false
            },
            //是否SP
            isSP: {
                type: Boolean,
                required: true,
                default: true
            },
            //试算ID
            quotationId: {
                type: String,
            },
            //是否审核
            isApprove: {
                type: Boolean,
                required: true,
                default: true
            },
            //审核状态【add,edit,view】
            auditOp: {
                type: String,
                required: true,
                default: 'view'
            },
            //申请编号
            applyNo: {
                type: String,
            },
            //合同编号
            contractNo: {
                type: String,
            },
            //试算清单信息
            contractForm: {
                type: Object,
            },
            //是否满六期
            isSixPeriod: {
                type: Boolean,
                required: true,
                default: false
            },
            //基本数据
            Obj: {
                type: Object,
            }
        },
        data() {
            return {
                readonly: true,
                readonlyView: false,
                calForm: {},
                calFormShow: {
                    calculateTime: "",//请求日期
                    executeTime: "",//计算日期
                    prepaymentType: "",//提前终止原因
                    repayMode: "",//还款方式
                    shortSixPeriodReason: "",//不满六期原因
                },
                resultForm: {},
                resultFormShow: {
                    unpayedCaptial: 0,//未偿本金
                    overdueAmount: 0,//逾期租金
                    interestReceivable: 0,//利息应收
                    unpayedOverdueInterest: 0,//未付逾期利息
                    prepaymentCharge: 0,//提前终止费用
                    overdueInterestReceivable: 0,//应计逾期利息
                    prepaymentCost: 0,//提前终止金额
                    otherCost: 0,//杂费
                    unusedDeposit: 0,//未分配金额
                    exemptBillCost: 0,//豁免单费用
                    exemptAmount: 0,//豁免费用
                    exemptOverdueInterest: 0,//豁免罚息
                    receivableAmount: 0,//应收金额
                },
                contractStatusList: [],//获取合同状态
                prepaymentTypeList: [],//获取提前终止原因
                repayModeList: [],//还款方式
                //计算日期规则
                rulesCalForm: {
                    executeTime: [{required: true, message: "计算日期不能为空", trigger: "blur", type: 'date'}],
                    prepaymentType: [{required: true, message: "提前终止原因不能为空", trigger: "blur"}],
                    repayMode: [{required: true, message: "还款方式不能为空", trigger: "blur"}],
                    shortSixPeriodReason: [{required: true, message: "不满六期原因不能为空", trigger: "blur"}],
                },
                //计算日期只能选择当天之后的
                optionsexecuteTime: {
                    disabledDate(date) {
                        return date && date.valueOf() < new Date();
                    }
                },
                //开始日期
                startDate: new Date(),
                //弹窗展示
                isShow: false,
                titleModal: "详情",
                //未付逾期利息展示
                isShowBasicRepaymentPlan: false,
                // basicRepaymentPlanColumns:['termNo','dueDate','receivableInterest'],
                basicRepaymentPlanColumns: ['termNo', 'totalPenalty'],
                //应计逾期利息展示
                isShowBasicPenaltyInterest: false,
                basicPenaltyInterestColumns: ['termNo', 'totalPenalty'],
                //杂费展示
                isShowOtherCost: false,
                basicExpenseRecordColumns: ['costType', 'remainingAmt'],
                //豁免费用展示
                isShowExemptAmount: false,
                manageCostExemptColumns: ['costType', 'costAmount', 'exemptionAmount'],
                //豁免罚息展示
                isShowExemptOverdueInterest: false,
                managePenaltyExemptColumns: ['totalPenalty', 'exemptionAmt'],
                //豁免单费用范围
                exemptBillCostMax: 0,//最大豁免单费用
                exemptBillCostMin: 0,//最小豁免单费用

                //是否计算
                isCal: false,

                //是否展示附件
                isUploadFileModalOpen: false,
                fileParams: {},

                //提前终止费率
                prepaymentRate: 0,
            }
        },
        created() {
            this.refreshCom();
        },
        mounted() {
            if (this.Obj.prepaymentRequestTime) {
                this.initExemptAmountDetail();
                this.initExemptOverdueInterestDetail();
            }
        },
        methods: {
            initExemptAmountDetail() {
                var queryData = {
                    pageSize: 9999,
                    pageNumber: 1,
                    condition: {}
                };
                let exemptionAmount = 0;
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                queryData["condition"]["calculateTime"] = this.Obj.prepaymentRequestTime;
                queryExemptAmountDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        if (res.data) {
                            res.data.records.forEach(e => {
                                exemptionAmount = exemptionAmount + e.exemptionAmount;
                            });
                            this.resultForm.exemptAmount = exemptionAmount;
                        }
                    }
                });
            },
            initExemptOverdueInterestDetail(queryData) {
                var queryData = {
                    pageSize: 9999,
                    pageNumber: 1,
                    condition: {}
                };
                let exemptionAmt = 0;
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                queryData["condition"]["calculateTime"] = this.Obj.prepaymentRequestTime;
                queryExemptOverdueInterestDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        if (res.data) {
                            res.data.records.forEach(e => {
                                exemptionAmt = exemptionAmt + e.exemptionAmt;
                            });
                            this.resultForm.exemptOverdueInterest = exemptionAmt;
                        }
                    }
                });
            },
            //页面跳转进入初始化
            refreshCom() {
                this.initDatadic();//初始化数据字典
                if ("add" == this.op) {
                    this.initialize();
                } else if ("edit" == this.op) {
                    this.queryStaySettle();
                } else if ("view" == this.op) {
                    this.queryStaySettle();
                    this.readonlyView = true;
                }
                //日结日期获取
                getBatchDate(this.contractNo).then(res => {
                    if (res.code === "0000") {
                        // console.info(JSON.stringify(res.data))
                        // console.info(res.data.batchDate,new Date(res.data.batchDate),new Date(Date.parse(res.data.batchDate)))
                        var batchDate = res.data.batchDate;
                        var lastBatchDate = res.data.lastBatchDate;
                        // console.info(batchDate.slice(0,4),batchDate.slice(4,6),batchDate.slice(6,8))
                        this.optionsexecuteTime = {
                            disabledDate(date) {
                                return (date && date.valueOf() < new Date(batchDate.slice(0, 4), batchDate.slice(4, 6) - 1, batchDate.slice(6, 8)))
                                     || (date && date.valueOf() >= new Date(lastBatchDate.slice(0, 4), lastBatchDate.slice(4, 6) - 1, lastBatchDate.slice(6, 8)));
                            }
                        };
                        if ("add" == this.op) {
                            this.calForm.calculateTime = new Date(batchDate.slice(0, 4), batchDate.slice(4, 6) - 1, batchDate.slice(6, 8));
                            this.calForm.executeTime = new Date(batchDate.slice(0, 4), batchDate.slice(4, 6) - 1, batchDate.slice(6, 8));
                        }
                        this.startDate = new Date(batchDate.slice(0, 4), batchDate.slice(4, 6) - 1, batchDate.slice(6, 8));
                    }
                });
                this.getPrepaymentRate();
            },
            //初始化
            initialize() {
                this.calForm = this.calFormShow;
                this.resultForm = this.resultFormShow;
            },
            //退回
            close() {
                this.$emit('next', "退回");
                this.initialize();
            },
            //获取提前终止费率
            getPrepaymentRate() {
                getPrepaymentRate({contractNo: this.contractNo}).then(res => {
                    if (res.code === '0000') {
                        this.prepaymentRate = res.data;
                        console.info("提前终止费用比率" + res.data, this.prepaymentRate);
                    }
                });
            },
            //计算
            calCost() {
                if (this.applyNo != null && this.applyNo != '') {
                    this.$refs.showCalForm.validate(valid1 => {
                        if (valid1) {
                            let param = this.calForm;
                            param.applyNo = this.applyNo;
                            param.contractNo = this.contractNo;
                            param.exemptBillCost = this.resultForm.exemptBillCost;
                            console.info("计算开始：" + JSON.stringify(param))
                            calSettleResult(param).then(res => {
                                if (res.code === "0000") {
                                    this.resultForm = res.data;//计算结果
                                    this.exemptBillCostMax = res.data.exemptBillCostMax;//最大豁免单费用
                                    this.exemptBillCostMin = res.data.exemptBillCostMin;//最小豁免单费用
                                    this.$Message.success("计算成功");

                                    //计算
                                    this.isCal = true;
                                    //返回信息
                                    this.backInfo();
                                } else {
                                    this.$Message.error("计算失败");
                                }
                            });
                        } else {
                            console.log('填写计算信息！');
                            this.$Message.warning("请填写计算信息");
                        }
                    });
                } else {
                    this.$Message.warning("请选择正确的申请单！");
                }
            },
            backInfo() {
                //返回信息
                this.contractForm.isCal = true;
                let param = JSON.parse((JSON.stringify(this.contractForm) + JSON.stringify(this.calForm)).replace(/}{/, ','));
                param = JSON.parse((JSON.stringify(param) + JSON.stringify(this.resultForm)).replace(/}{/, ','));
                console.info(JSON.stringify(param));
                this.$emit('backInfo', param);
            },
            //查询测算信息
            queryStaySettle() {
                getStaySettleDetailById(this.quotationId).then(res => {
                    if (res.code === "0000") {
                        // console.info("查询测算信息:"+JSON.stringify(res.data));
                        this.calForm = res.data;
                        this.resultForm = res.data;
                        this.backInfo();
                    }
                });
            },
            //数据字典
            initDatadic() {
                //获取提前终止原因/获取还款方式
                getDictDataByType("prepaymentType").then(res => {
                    if (res.code === "0000") {
                        this.prepaymentTypeList = res.data;
                    }
                });
                getDictDataByType("receiptSourceType").then(res => {
                    if (res.code === "0000") {
                        this.repayModeList = res.data;
                    }
                });
            },
            queryList(tab) {
                if (tab == 'tableUnpayedOverdueInterest') {
                    this.$refs['tableUnpayedOverdueInterest'].reloadData();
                }
                if (tab == 'tableOverdueInterestReceivable') {
                    this.$refs['tableOverdueInterestReceivable'].reloadData();
                }
                if (tab == 'tableOtherCost') {
                    this.$refs['tableOtherCost'].reloadData();
                }
                if (tab == 'tableExemptAmount') {
                    this.$refs['tableExemptAmount'].reloadData();
                }
                if (tab == 'tableExemptOverdueInterest') {
                    this.$refs['tableExemptOverdueInterest'].reloadData();
                }
            },

            //查询未付逾期利息详情
            queryUnpayedOverdueInterestDetail(queryData) {
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                console.info(JSON.stringify(queryData));
                queryUnpayedOverdueInterestDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        let result = [];
                        records.forEach(column => {
                            column.totalPenalty = column.totalPenalty - column.receivedAmt - column.realExemptionAmt;
                            result.push(column);
                        });
                        // console.info("查询未付逾期利息详情"+JSON.stringify(result))
                        this.$refs.tableUnpayedOverdueInterest.updateTableData(result, total);
                        //弹窗打开
                        this.isShow = true;
                        this.isShowBasicRepaymentPlan = true;
                    }
                });
            },
            //查询应计逾期利息详情
            queryOverdueInterestReceivableDetail(queryData) {
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                queryOverdueInterestReceivableDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.tableOverdueInterestReceivable.updateTableData(records, total);
                        //弹窗打开
                        this.isShow = true;
                        this.isShowBasicPenaltyInterest = true;
                    }
                });
            },
            //查询杂费详情
            queryOtherCostDetail(queryData) {
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                queryOtherCostDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.tableOtherCost.updateTableData(records, total);
                        //弹窗打开
                        this.isShow = true;
                        this.isShowOtherCost = true;
                    }
                });
            },
            //查询豁免费用
            queryExemptAmountDetail(queryData) {
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                queryData["condition"]["calculateTime"] = this.Obj.prepaymentRequestTime;
                queryExemptAmountDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.tableExemptAmount.updateTableData(records, total);
                        //弹窗打开
                        this.isShow = true;
                        this.isShowExemptAmount = true;
                    }
                });
            },
            //查询豁免罚息
            queryExemptOverdueInterestDetail(queryData) {
                //结果查询
                queryData["condition"]["contractNo"] = this.contractNo;
                queryData["condition"]["calculateTime"] = this.Obj.prepaymentRequestTime;
                queryExemptOverdueInterestDetail(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.tableExemptOverdueInterest.updateTableData(records, total);
                        //弹窗打开
                        this.isShow = true;
                        this.isShowExemptOverdueInterest = true;
                    }
                });
            },
            //关闭弹窗
            closeModle() {
                this.isShowBasicRepaymentPlan = false;
                this.isShowBasicPenaltyInterest = false;
                this.isShowOtherCost = false;
                this.isShowExemptAmount = false;
                this.isShowExemptOverdueInterest = false;
                this.isShow = false;
            },
            //保存
            save() {
                let param = JSON.parse((JSON.stringify(this.contractForm) + JSON.stringify(this.calForm)).replace(/}{/, ','));
                param = JSON.parse((JSON.stringify(param) + JSON.stringify(this.resultForm)).replace(/}{/, ','));
                console.info(JSON.stringify(param));

                if (this.isCal) {
                    saveStaySettle(param).then(res => {
                        if (res.code === "0000") {
                            console.info(JSON.stringify(res.data));
                            this.calForm = res.data;
                            this.resultForm = res.data;
                            this.$Message.success("保存成功");
                        }
                    });
                } else {
                    this.$Message.warning("请先计算！");
                }
            },
            //跳转到豁免费用页面
            skipToExempt() {
                this.afs.newTab(this, "projects/basic/pages/contract/fee-waiver/cost-exempt-bill-detial/index",
                    "费用豁免单新增", "ios-add", this.Obj, this.contractNo + 1, [], true
                );
            },
            //豁免单费用变更
            exemptBillCostChange() {
                if (this.applyNo != null && this.applyNo != '') {
                    this.$refs.showCalForm.validate(valid1 => {
                        if (valid1) {
                            let param = this.calForm;
                            param.applyNo = this.applyNo;
                            param.contractNo = this.contractNo;
                            param.exemptBillCost = this.resultForm.exemptBillCost;
                            calSettleResult(param).then(res => {
                                if (res.code === "0000") {
                                    this.resultForm.exemptAmount = res.data.exemptAmount;//豁免费用
                                    this.resultForm.exemptOverdueInterest = res.data.exemptOverdueInterest;//豁免罚息
                                    this.resultForm.receivableAmount = res.data.receivableAmount;//应收金额

                                    this.exemptBillCostMax = res.data.exemptBillCostMax;//最大豁免单费用
                                    this.exemptBillCostMin = res.data.exemptBillCostMin;//最小豁免单费用
                                    //计算
                                    this.isCal = true;
                                    //返回信息
                                    this.backInfo();
                                } else {
                                    this.$Message.error("计算失败");
                                }
                            });
                        } else {
                            console.log('填写计算信息！');
                            this.$Message.warning("请填写计算信息");
                        }
                    });
                } else {
                    this.$Message.warning("请选择正确的申请单！");
                }
            },
            //打开附件信息
            openUploadModal() {
                this.fileParams = {
                    belongNo: this.Obj.contractNo,
                    busiNo: this.Obj.caseNo || 'advanceSettle',
                    busiType: 'advanceSettle',
                    busiData: {},
                    busiNodes: 'advanceSettle' //业务节点
                };
                this.isUploadFileModalOpen = true;
            },
            //关闭附件信息
            closeModal() {
                this.isUploadFileModalOpen = false;
            },
        },
        computed: {
            defines() {
                return [
                    {
                        id: "defineBasicRepaymentPlan",
                        fields: basicRepaymentPlanDefine
                    },
                    {
                        id: "defineBasicPenaltyInterest",
                        fields: basicPenaltyInterestDefine
                    },
                    {
                        id: "defineBasicExpenseRecord",
                        fields: basicExpenseRecordDefine
                    },
                    {
                        id: "defineManageCostExempt",
                        fields: manageCostExemptDefine
                    },
                    {
                        id: "defineManagePenaltyExempt",
                        fields: managePenaltyExemptDefine
                    },
                ];
            }
        },

    }
</script>

<style scoped>
    .basis-info >>> .ivu-input[disabled] {
        color: black;
    }

    .basis-info >>> .ivu-select-disabled .ivu-select-selected-value {
        color: #515a6e;
    }

    .basis-info >>> .ivu-input-number-input[disabled] {
        color: black;
    }
</style>
